package com.example.base.net

import com.example.base.entity.AddEntity
import com.example.base.entity.CarEntity
import com.example.base.entity.CategoryEntity
import com.example.base.entity.CommentEntity
import com.example.base.entity.CreateOrderEntity
import com.example.base.entity.GetPreOderEntity
import com.example.base.entity.GoodsEntity
import com.example.base.entity.IndexEntity
import com.example.base.entity.LoginEntityResult
import com.example.base.entity.OrderEntity
import com.example.base.entity.ParamCreateOrder
import com.example.base.entity.ParamPay
import com.example.base.entity.ParamPreOrder
import com.example.base.entity.ParamSend
import com.example.base.entity.ParamSendChild
import com.example.base.entity.PayResult
import com.example.base.entity.PreOrderEntity
import com.example.base.entity.Reply
import com.example.base.entity.ReplyEntity
import com.example.base.entity.ReplyEntityItem
import com.example.base.entity.SendCodeEntity
import com.example.base.entity.SendCodeEntityResult
import com.example.base.entity.UpdatePwdEntityResult
import com.example.base.entity.UserEntityResult
import com.example.base.entity.XqEntity
import com.example.base.mvvm.BaseModel
import com.example.base.mvvm.Res
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiServer {
    /**
     * 所有的请求均使用协程方式
     */
    @POST(Cons.SEND_CODE_URL)
    suspend fun sendCode(@Query("phone") phone: String): BaseModel<SendCodeEntity>

    @POST(Cons.LOGIN_CODE_URL)
    suspend fun loginCode(@Body body: RequestBody): LoginEntityResult//验证码登录

    @POST(Cons.LOGIN_URL)
    suspend fun login(@Body body: RequestBody): LoginEntityResult//密码登录

    @GET(Cons.USER_URL)
    suspend fun user(): UserEntityResult//获取用户信息

    @POST(Cons.UPDATE_PWD_URL)
    suspend fun updatePwd(@Body body: RequestBody): BaseModel<Boolean>

    @GET(Cons.INDEX_URL)
    suspend fun index(): BaseModel<IndexEntity>

    @GET(Cons.INDEX_GOODS_URL)
    suspend fun indexGoods(
        @Path("type") type: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): BaseModel<GoodsEntity>

    //搜索
    @GET(Cons.GOODS_URL)
    suspend fun search(
        @Query("keyword") keyword: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): BaseModel<GoodsEntity>

    //详情
    @GET(Cons.XQ_URL)
    suspend fun xq(@Path("id") id: Int, @Query("type") type: String): BaseModel<XqEntity>

    @GET(Cons.TUIJIAN_URL)//详情中的推荐
    suspend fun tuijian(
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): BaseModel<GoodsEntity>

    @POST(Cons.ADD_URL)
    suspend fun addCar(@Body body: RequestBody): BaseModel<AddEntity>

    @GET(Cons.CAR_URL)
    suspend fun car(
        @Query("isValid") isValid: String,
        @Query("limit") limit: String,
        @Query("page") page: String
    ): BaseModel<CarEntity>

    @POST(Cons.UPDATE_URL)
    suspend fun update(@Query("id") id: Int, @Query("number") number: Int): BaseModel<String?>

    @POST(Cons.DELETE_URL)
    suspend fun delete(@Query("ids") ids: Array<Int>): BaseModel<String?>

    @GET(Cons.CATEGORY_URL)
    suspend fun category(): BaseModel<CategoryEntity>

    @GET(Cons.GOODS_URL)
    suspend fun cateGoryGoods(
        @Query("cid") cid: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): BaseModel<GoodsEntity>

    @GET(Cons.COMMENT_URL)
    suspend fun comment(
        @Path("id") id: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int,
        @Query("type") type: String
    ): BaseModel<CommentEntity>
    //预下单
    @POST(Cons.PREORDER_URL)
    suspend fun preOrder(@Body body:ParamPreOrder):BaseModel<PreOrderEntity>

    @GET(Cons.GETPREORDER_URL)
    suspend fun getPreOrder(@Path("preOrderNo")preOrderNo:String):BaseModel<GetPreOderEntity>

    @POST(Cons.CREATEORDER_URL)
    suspend fun createOrder(@Body body:ParamCreateOrder):BaseModel<CreateOrderEntity>
    @POST(Cons.PAY_URL)
    suspend fun pay(@Body body:ParamPay):BaseModel<PayResult>
    @GET(Cons.ORDER_URL)
    suspend fun order(@Query("type")type:String,  @Query("limit") limit: Int,
                      @Query("page") page: Int):BaseModel<OrderEntity>





    //i视频相关
    @GET(Cons.REPLY_URL)
    suspend fun reply(@Query("datatype")datatype:Int,@Query("itemid")itemid:String):Res<ReplyEntity>
    @POST(Cons.SEND_URL)
    suspend fun send(@Body body:ParamSend):Res<ReplyEntityItem>
    @POST(Cons.SEND_CHILD_URL)
    suspend fun sendChild(@Body body:ParamSendChild):Res<Reply>


    //分类详情
    @GET(Cons.GOODS_URL)
    suspend fun cateXq(
        @Query("cid") cid: Int,
        @Query("priceOrder") priceOrder: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): BaseModel<GoodsEntity>
}